package com.yifeng.repo.base.security.context.manager;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by daibing on 2023/3/17.
 */
public class RequestHeaderManager {
    public static final String REQ_METHOD = "_req_method";
    public static final String REQ_URL = "_req_url";
    public static final String REQ_URI = "_req_uri";
    public static final String REQ_CONTENT_TYPE = "_req_content_type";
    public static final String REQ_IP = "_req_ip";
    public static final String REQ_HOST = "_req_host";

    private static final ThreadLocal<Map<String, String>> HEADER_MAP_HOLDER = ThreadLocal.withInitial(HashMap::new);

    public static void set(String key, String value) {
        HEADER_MAP_HOLDER.get().put(key, value);
    }

    public static String get(String key) {
        return HEADER_MAP_HOLDER.get().get(key);
    }

    public static Set<String> keySet() {
        return HEADER_MAP_HOLDER.get().keySet();
    }

    public static Map<String, String> all() {
        return HEADER_MAP_HOLDER.get();
    }

    public static void clear(String key) {
        HEADER_MAP_HOLDER.get().remove(key);
    }

    public static void clear() {
        HEADER_MAP_HOLDER.remove();
    }
}
